package log4j;

import file.UtilFile;
import org.apache.log4j.Logger;
import org.apache.log4j.xml.DOMConfigurator;

import java.io.IOException;
import java.net.URISyntaxException;

/**
 * 以xml形式配置log4j ，需要 配置文件，文件位置为classpath/config/log4j/log4j.xml
 * Description: log4j
 * Created by 4790K_NSL on 2017/5/20.
 */
public class UtilLog4j {
    static{
        String xmlPath="config/log4j/log4j.xml";
        //通过classpath为基准目录，定位资源
        String absPath= null;
        try {
            absPath = UtilFile.getAbsPathBaseOnClassPath(xmlPath);
        } catch (URISyntaxException e) {
            e.printStackTrace();
        }
        //System.out.println(absPath);
        DOMConfigurator.configure(absPath);
    }

    static public Logger getRootLogger(){
        return  Logger.getRootLogger();
    }

    static public Logger getLogger(Class clazz){
        return Logger.getLogger(clazz);
    }


    public static void main(String args[]) throws IOException {
        Logger logger=getRootLogger();
        logger.debug("Here is some DEBUG");
        logger.info("Here is some INFO");
        logger.warn("Here is some WARN");
        logger.error("Here is some ERROR");
        logger.fatal("Here is some FATAL");
    }
}
